STEP 17: We will now add newrise to bally to get the new y-coordinate for the soccerball.

  • In , drag out Addition.
  • Change my_var to end_y, and replace 2 + 3 with newrise + bally!

We now have a new y-coordinate for our ball. We will use netx as our x-coordinate, since we want the ball to move towards the net, but end_y as the y-coordinate so that the ball only hits the net if the user was correct!

To navigate the page using the TAB key, first press ESC to exit the code editor.

stage.set_axis(100) stage.create_grid_overlay(10, "grey") stage.set_background("soccerfield") ballx = -80 bally = random.randint(-100,100) # sprite = codesters.Sprite("image", x, y) ball = codesters.Sprite("soccerball", ballx, bally) netx = 90 nety = random.randint(-100,100) # sprite = codesters.Sprite("image", x, y) net = codesters.Sprite("soccernet", netx, nety) net.flip_right_left() #sprite = codesters.Line(x-start, y-start, x-end, y-end, "color") line = codesters.Line(ballx, bally, netx, nety, "blue") slopeguess = float(line.ask("What is the slope of this line?")) rise = nety - bally run = netx - ballx slope = rise / run # sprite = codesters.Text("text", x, y) sprite = codesters.Text(slope, 0, 30) newrise = slopeguess*run
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)